package com.lxd.order.web;


import com.lxd.order.feign.clients.UserClient;
import com.lxd.order.pojo.Consume;
import com.lxd.order.pojo.Order;
import com.lxd.order.service.OrderService;
import com.lxd.pojo.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.swing.text.StyledEditorKit;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

   @Autowired
   private OrderService orderService;
   @Autowired
   private UserClient userClient;

   @GetMapping("{orderId}")
   @HystrixCommand(fallbackMethod = "queryOrderByUserIdFallback")
   public Order queryOrderByUserId(@PathVariable("orderId") Long orderId) throws InterruptedException {
      // 根据id查询订单并返回
      Order order = orderService.queryOrderById(orderId);
      return order;
   }

   @PostMapping("/consume")
   public boolean consume(@RequestBody Consume consume){
      log.info("consume:{}",consume);
      boolean result= orderService.consume(consume);
      return result;
   }



   //override the fallback method
   private Order queryOrderByUserIdFallback(Long orderId){
      log.info("queryOrderByUserId Fallback:{}",orderId);
      return null;
   }


}
